package com.huaxin.device.mapping;

import com.huaxin.device.dto.request.AddDeviceModelReqDTO;
import com.huaxin.device.dto.request.UpdateDeviceModelReqDTO;
import com.huaxin.device.models.DeviceModel;
import com.huaxin.hxenum.enums.DeviceType;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface DeviceModelMapping {

    @Mapping(target = "deviceType", ignore = true)
    DeviceModel toEntity(AddDeviceModelReqDTO in);

    @AfterMapping
    default void afterMapping(AddDeviceModelReqDTO in, @MappingTarget DeviceModel entity) {
        entity.setDeviceType(DeviceType.of(in.getDeviceType()));
    }

    @Mapping(target = "deviceType", ignore = true)
    void updateEntity(UpdateDeviceModelReqDTO in, @MappingTarget DeviceModel entity);

    @AfterMapping
    default void afterMapping(UpdateDeviceModelReqDTO in, @MappingTarget DeviceModel entity) {
        entity.setDeviceType(DeviceType.of(in.getDeviceType()));
    }
}